import request from '@/utils/request'
import store from '@/store'
// 接口方法, 只负责调用一个接口, 返回一个Promise对象
// 获取频道数据接口
export const getUserChannelListAPI = () => {
  return request({
    url: '/v1_0/user/channels',
    method: 'GET',
    headers: {
      Authorization: 'Bearer ' + store.state.user.token
    }
  })
}

// 获取文章列表接口
export const getArticleListAPI = ({ channelId, timestamp = Date.now() }) => {
  return request({
    url: '/v1_0/articles',
    method: 'GET',
    params: {
      channel_id: channelId,
      timestamp
    }
  })
}

// 文章 - 不感兴趣
export const articleDislikeAPI = ({ artId }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    headers: {
      Authorization: 'Bearer ' + store.state.user.token
    },
    data: {
      target: artId
    }
  })
}

// 文章 - 举报文章
export const articleReportsAPI = ({ target, type, remark }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    headers: {
      Authorization: 'Bearer ' + store.state.user.token
    },
    data: {
      target,
      type,
      remark
    }

  })
}

// 首页 - 获取所有频道列表
export const getAllChannelListAPI = () => {
  return request({
    url: '/v1_0/channels',
    method: 'GET'
  })
}

// 首页 - 跟新用户频道列表
export const updateUserChannelListAPI = ({ channels }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    headers: {
      Authorization: 'Bearer ' + store.state.user.token
    },
    data: {
      channels
    }
  })
}
